% version2 ：损耗计算参考自论文；input1: 单个电机发挥的牵引力 kN, input2: 列车速度 km/h
function [stator_loss, rotor_loss, total_loss, eta] = getmotorlossv2(Fpmt,v)
gearRatio = 2.517;  %减速比 cr400bf = 2.517
torque_r = 1455.7;  %额定转矩N*m 1236
rpm_r = 4100; %rpm
rpm_max = 5600;
Pout_r = 625; %额定功率 600

Pcu_r = 20.8; %额定铜耗 20
Pfe_r = 12.5; %额定铁耗 12
Peddy_r = 7.5; %额定涡流损耗 猜的
Phys_r = 5; %额定磁滞损耗 猜的
Pmech_r = 6; %额定机械损耗 1%Pr

wheel_D = 0.92; %车轮直径
%计算当前转速、转矩、功率
rpm_a = v/3.6*60 / (pi*wheel_D) * gearRatio;  %轮子转速->实际电机转速
torque_a = Fpmt * 1000 * (wheel_D/2) / gearRatio; %电机输出转矩
pout_a = Fpmt * v / 3.6; %kW

%先判断在不在运行
if Fpmt == 0 || rpm_a == 0
    stator_loss = 0;
    rotor_loss = 0;
    total_loss = 0;
    eta = 0;
    return;
end

% %计算方式一（简化版）:
% pcu_a = (torque / torque_r)^2 * Pcu_r;
% pfe_a = (rpm_a/rpm_r)^1.9 * Pfe_r;

%计算方式二（参考自文献）:
if rpm_a < rpm_r 
    pcu_a = (abs(pout_a)/rpm_a * rpm_r/Pout_r)^2 * Pcu_r;
    pfe_a = (rpm_a/rpm_r)^2*Peddy_r + (rpm_a/rpm_r) * Phys_r;
else
    pcu_a = (abs(pout_a)/Pout_r)^2 * Pcu_r;
    pfe_a = Peddy_r + (rpm_a/rpm_r)^1.6 * Phys_r;
end
pmech_a = (rpm_a/rpm_r)^2*Pmech_r;
%计算定转子损耗
% stator_loss = 1/4.3*pcu_a + 0.1*pfe_a;  % 1:3.3
% rotor_loss = 3.3/4.3*pcu_a + 0.9*pfe_a;
stator_loss = 1/4.3*pcu_a + 0.9*pfe_a;  
rotor_loss = 3.3/4.3*pcu_a + 0.1*pfe_a;
total_loss = pcu_a + pfe_a + pmech_a;

% 计算效率：牵引时——输入电能转换为动能的; 制动时——电机侧动能转换为可用电能的效率（减去了回馈制动过程的热耗）
if Fpmt==0
    eta = 1;
elseif Fpmt > 0
    eta = pout_a/(total_loss+pout_a);
elseif Fpmt < 0
    eta = (-pout_a-total_loss) / -pout_a;
    if(eta < 0)
        eta = 0;
        % total_loss = -pout_a;
    end
end